home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Browsers, Managers & Extensions / Firefox Backup Extension 6.0.3 / chrome / febe.jar / content / febeQuickBu.js < prev    next >
Text File  |  2008-08-18  |  8KB  |  226 lines

  1. // author: Chuck Baker
  2. // contact: febe@customsoftwareconsult.com
  3. // Version 6.0
  4.  
  5. var febeNameGuidxref = {};
  6.  
  7. function febeBuildList(){
  8.     // Clear the list
  9.     var theList = document.getElementById("febeExtList");
  10.     var children = theList.childNodes;
  11.     var n = children.length;
  12.     // Clear existing items
  13.     for (var i = 0; i < n; i++) {
  14.         theList.removeChild(children[0]);
  15.     }//for
  16.     
  17.     febeQuBuList();
  18.     
  19.     // Sort the list
  20.     var sortArray = [];
  21.     for(var i in febeExtensionsList){
  22.         sortArray.push(febeExtensionsList[i].Name);
  23.     }//for
  24.     sortArray.sort();
  25.     
  26.     for(var i in sortArray){
  27.         var data = febeExtensionsList[febeNameGuidxref[sortArray[i]]];
  28.         
  29.         var row = document.createElement('listitem');
  30.         
  31.         row.setAttribute('id', data.Guid );
  32.         row.setAttribute('type', "checkbox" );
  33.         var fxver = "(Fx ver "+data.Minversion+" - "+data.Maxversion+")";
  34.         row.setAttribute('label', data.Name+"{"+data.Version+"}  "+fxver );
  35.         row.setAttribute('checked', "false" );
  36.         if(data.Type == 2){
  37.             row.setAttribute('style', "color: blue;" );
  38.         }else{
  39.             row.setAttribute('style', "color: green;" );
  40.         }//if
  41.         if(data.isDisabled) row.setAttribute('style', "color: grey;" );
  42.         theList.appendChild( row );
  43.  
  44.     }//for
  45.     document.getElementById("febeSelectAllID").setAttribute("disabled","false");
  46.     document.getElementById("febeDeselectAllID").setAttribute("disabled","false");
  47.     return true;
  48. }//febeBuListWindow()
  49.  
  50. function febeSelect(bool){
  51.   // Select/deselect all
  52.     for(var i in febeExtensionsList){
  53.         var item = document.getElementById(i);
  54.         if(item){item.setAttribute("checked",bool);}
  55.     }//for
  56. }//febeSelect()
  57.  
  58. function febeSaveList(){
  59.  
  60. }//febeSaveList()
  61.  
  62. function febeQuBuList(){
  63.   //Get a list of all installed extensions/themes
  64.     febeProfDir = Components.classes["@mozilla.org/file/directory_service;1"]
  65.         .getService(Components.interfaces.nsIProperties)
  66.         .get("ProfD", Components.interfaces.nsIFile);
  67.     febeProfDir.append("extensions");
  68.     var extDir = febeProfDir.clone();
  69.     var entries = extDir.directoryEntries;
  70.     febeExtensionsList = {};
  71.  
  72.     while(entries.hasMoreElements()){
  73.         var entry = entries.getNext();
  74.         entry.QueryInterface(Components.interfaces.nsIFile);
  75.         if(!entry.isDirectory()){continue;}    // Don't process junk in the extension directory
  76.  
  77.         var guid = entry.leafName;
  78.         var thisExt = new febeExtInfo(guid);
  79.         if(!thisExt) continue;
  80.         var eType = thisExt.type;                            // 2=Extension, 4=Theme
  81.         if(eType != 2 && eType != 4){continue;}            // Not an extension or theme ... what is it?
  82.         
  83.         var ext = new febeExtObj;
  84.         ext.Name = thisExt.name;
  85.         ext.Type = eType;
  86.         ext.Version = thisExt.version;
  87.         ext.Icon = thisExt.iconURL; 
  88.         ext.Home = thisExt.homepageURL; 
  89.         ext.Guid = guid; 
  90.         ext.verified = false;
  91.         ext.Include = false;
  92.         ext.isDisabled = thisExt.isDisabled; 
  93.         ext.Minversion = thisExt.minVersion;
  94.         ext.Maxversion = thisExt.maxVersion;
  95.         
  96.         var ePath = extDir.clone();
  97.         ePath.append(thisExt.guid)
  98.         ext.Path = ePath.path; 
  99.         
  100.         febeExtensionsList[guid] = ext;
  101.         febeNameGuidxref[thisExt.name] = guid; 
  102.         
  103.         var tmp = "";
  104.         tmp=febeExtensionsList[thisExt.guid].Name+"\n";
  105.         tmp+=febeExtensionsList[thisExt.guid].Version+"\n";
  106.         tmp+=febeExtensionsList[thisExt.guid].Path+"\n";
  107.         tmp+=febeExtensionsList[thisExt.guid].Icon+"\n";
  108.         tmp+=febeExtensionsList[thisExt.guid].Home+"\n";
  109.         tmp+=febeExtensionsList[thisExt.guid].Guid+"\n";
  110.         tmp+=febeExtensionsList[thisExt.guid].verified+"\n";
  111.         tmp+=febeExtensionsList[thisExt.guid].Include+"\n";
  112.         tmp+="type: "+eType+"\n";
  113.         //alert(tmp)
  114.         //if(i < 3) alert(tmp);
  115.     }//while
  116. }//febeQuBuList()
  117.  
  118. function febeQuickBu(){
  119.     febeProfDir = Components.classes["@mozilla.org/file/directory_service;1"]
  120.             .getService(Components.interfaces.nsIProperties)
  121.             .get("ProfD", Components.interfaces.nsIFile);
  122.     febeProfDir.append("extensions");
  123.     
  124.     var combined = document.getElementById("febeCreateSingleXPI").checked;
  125.     var combinedName = document.getElementById("febeCreateSingleXPIname").value +".xpi";
  126.     febeExBuDir = document.getElementById("febeQuickBuDir").value;
  127.     if(combined){
  128.         febeTmpDir = Components.classes["@mozilla.org/file/local;1"]
  129.                      .createInstance(Components.interfaces.nsILocalFile);
  130.         febeTmpDir.initWithPath(febeExBuDir);
  131.         febeTmpDir.append("QBuTmp")
  132.         if ((febeTmpDir.exists() && febeTmpDir.isDirectory())){febeTmpDir.remove(true);}
  133.         febeTmpDir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);
  134.     }//if
  135.     var cnt = 0;
  136.     for(var i in febeExtensionsList){
  137.         var which = document.getElementById(i);
  138.         if(which.getAttribute("checked") != "true"){continue;}        
  139.         var item = febeExtensionsList[i]
  140.         var extDir = febeProfDir.clone();
  141.         febeExtExt = ".xpi";
  142.         if(item.Type == 4){febeExtExt = ".jar"};
  143.         var extName = item.Name;
  144.         var extVer = febeStripSpaces(item.Version);
  145.         var extBuName = febeStripSpaces(extName)+"{" + extVer + "}"+febeExtExt;
  146.         var srcName = extDir.clone();
  147.         srcName.append(i);
  148.         srcName = srcName.path;
  149.         var destDir = febeExBuDir;
  150.         if(combined){destDir = febeTmpDir.path;}
  151.         febeZip(srcName,destDir,extBuName);
  152.         which.setAttribute("checked", false)
  153.         cnt++;
  154.     }//for
  155. //alert(febeZipFinished)
  156.     if(combined){
  157.         febeProfDir = Components.classes["@mozilla.org/file/directory_service;1"]
  158.             .getService(Components.interfaces.nsIProperties)
  159.             .get("ProfD", Components.interfaces.nsIFile);
  160.         febeProfDir.append("extensions");
  161.         febeProfDir.append(FEBE_GUID);
  162.         febeProfDir.append("!install.rdf");
  163.         var sourcefile = febeProfDir.path;
  164.         var destDir = febeTmpDir.path;
  165.         var dName = "install.rdf";
  166.         febeCopyFile(sourcefile,destDir,dName);    // Copy the install.rdf for the combined package
  167.         febeZip(febeTmpDir.path,febeExBuDir,combinedName);
  168.         //while(!febeZipFinished){;}
  169.  
  170.         var tmp = febeMsg[218].replace(/%NUM%/,cnt);
  171.         tmp = tmp.replace(/%FNAME%/,combinedName);
  172.         febeAlert(tmp);
  173.         febeTmpDir.remove(true);
  174.     }else{
  175.         var tmp = febeMsg[217].replace(/%NUM%/,cnt);
  176.         febeAlert(tmp);
  177.     }//if
  178.     return true;
  179. }//febeQuickBu()
  180.  
  181. function febeQuickBuLoad(){
  182.     febeSetMsgs();
  183.     var qbuDir = febeMsg[216];
  184.     var prefName = "extensions.febe.quickBuDir";
  185.     if(febePrefs.prefHasUserValue(prefName)){
  186.         qbuDir = febeGetUnicharPref(prefName);
  187.     }else{
  188.         var prefName = "extensions.febe.extBUdir";
  189.         if(febePrefs.prefHasUserValue(prefName)){
  190.             qbuDir =febeGetUnicharPref(prefName);
  191.         }//if
  192.     }//if
  193.     document.getElementById("febeQuickBuDir").value = qbuDir;
  194.     febeBuildList();
  195. }//febeQuickBuLoad()
  196.  
  197. function febeCreateSingleXPIcheck(that){
  198.     document.getElementById("febeCreateSingleXPIbox").hidden = !that.checked;
  199.     //sizeToContent();
  200. }//febeCreateSingleXPIcheck()
  201.  
  202. function febeQuickBuBrowse(){
  203.   // Select Quick backup destinaton directory
  204.     const nsIFilePicker = Components.interfaces.nsIFilePicker;
  205.     var fp = Components.classes["@mozilla.org/filepicker;1"]
  206.              .createInstance(nsIFilePicker);
  207.     fp.init(window, febeMsg[216], nsIFilePicker.modeGetFolder);
  208.     fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
  209.  
  210.     // Set default directory to current backup directory
  211.     var qbuDir = document.getElementById("febeQuickBuDir").value;
  212.     var dd = Components.classes["@mozilla.org/file/local;1"]
  213.              .createInstance(Components.interfaces.nsILocalFile);
  214.     dd.initWithPath(qbuDir);
  215.     fp.displayDirectory = dd;
  216.  
  217.     var rv = fp.show();
  218.     if (rv == nsIFilePicker.returnOK){
  219.         rv = fp.file;
  220.         qbuDir = rv.path;
  221.         febeSetUnicharPref("extensions.febe.quickBuDir", qbuDir);
  222.         document.getElementById("febeQuickBuDir").value = qbuDir;
  223.     }//if
  224.     return true;
  225. }//febeQuickBuBrowse()
  226.